<template>
  <div class="app-container teacher-form-container" >
    <div v-if="opt != 'add'">
      <el-descriptions title="">
        <el-descriptions-item label="企业名称">
          <el-tag style="margin-top: -5px" size="medium">{{
            obj != null ? obj.index : enterpriseName
          }}</el-tag>
              <el-button style="margin-left: 15px"
                type="success"
                plain
                icon="el-icon-search"
                size="mini"
                @click="queryCollaborative"
                >园区平台</el-button
              >
          <el-button type="danger" icon="el-icon-close" size="mini" @click="cancel">关 闭</el-button>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="企业信息" name="first">
        <el-form :model="form" ref="form" :rules="rules" label-width="100px">
          <el-row>
            <el-col :span="8">
              <el-form-item label="企业名称" prop="enterpriseName">
                <el-input
                  v-model="form.enterpriseName"
                  placeholder="请输入企业名称"
                  :disabled="opt == 'details'"
                  @change="handlerPageNo"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="行政区域" prop="administrativeArea">
                <Treeselect
                  v-model="form.administrativeArea"
                  :disabled="opt == 'details'"
                  :options="options"
                  :flat="true"
                  :show-count="true"
                  :normalizer="normalizer"
                  placeholder="请选择行政区域"
                  @input="administrativeAreaChange"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="所属园区" prop="parkName">
                <el-select
                  v-model="form.parkName"
                  style="width: 305px"
                  placeholder="请选择所属园区"
                  :disabled="opt == 'details'"
                >
                  <el-option
                    v-for="dict in dict.type.belong_to_park"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>

              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="公司编号" prop="enterpriseNo">
                <el-input
                  v-model="form.enterpriseNo"
                  :placeholder="noNew"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="所属行业" prop="industry">
                <treeselect
                  v-model="form.industry"
                  :options="industryOptions"
                  :normalizer="industryNormalizer"
                  :searchable="true"
                  :clearable="true"
                  placeholder="请选择所属行业"
                  style="width: 100%"
                  :disabled="opt == 'details'"
                  @input="handleIndustryChange"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="企业性质" prop="enterpriseNature">
                <el-select
                  v-model="form.enterpriseNature"
                  style="width: 305px"
                  placeholder="请选择企业性质"
                  :disabled="opt == 'details'"
                >
                  <el-option
                    v-for="dict in dict.type.enterprise_nature"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="企业来源" prop="enterpriseSource">
                <el-select
                  v-model="form.enterpriseSource"
                  style="width: 305px"
                  placeholder="请选择企业来源"
                  :disabled="opt == 'details' || form.enterpriseSource == 14"
                >
                  <el-option
                    v-for="dict in dict.type.enterprise_source"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <el-form-item label="详细地址" prop="enterpriseAddress">
                <el-input
                  v-model="form.enterpriseAddress"
                  placeholder="请输入详细地址"
                  :disabled="opt == 'details'"
                  maxlength="400"
                  show-word-limit
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="注册资金" prop="registeredCapital">
                <el-col
                  ><el-input
                    v-model="form.registeredCapital"
                    placeholder="请输入注册资金"
                    :disabled="opt == 'details'"
                    maxlength="40"
                    show-word-limit
                > <template #append>万元</template></el-input>
                </el-col>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="法人代表" prop="legalRepresentative">
                <el-input
                  v-model="form.legalRepresentative"
                  placeholder="请输入法人代表"
                  :disabled="opt == 'details'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="成立日期" prop="establishmentDate">
                <el-date-picker
                  clearable
                  :disabled="opt == 'details'"
                  style="width: 305px"
                  v-model="form.establishmentDate"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="请选择成立日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row> </el-row>
          <el-row>

            <el-col :span="8">
              <el-form-item label="税务号" prop="taxId">
                <el-input
                  v-model="form.taxId"
                  placeholder="请输入税务号"
                  :disabled="opt == 'details'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="开户账号" prop="bankNo">
                <el-input
                  v-model="form.bankNo"
                  placeholder="请输入开户账号"
                  :disabled="opt == 'details'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="开户银行" prop="bankName">
                <el-input
                  v-model="form.bankName"
                  placeholder="请输入开户银行"
                  :disabled="opt == 'details'"
                />
              </el-form-item>
            </el-col>
          </el-row>
            <el-row>
              <el-col :span="8">
              <el-form-item label="联系人" prop="contacts">
                <el-input
                  v-model="form.contacts"
                  placeholder="请输入联系人"
                  :disabled="opt == 'details'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="联系电话" prop="telephone">
                <el-input
                  v-model="form.telephone"
                  placeholder="请输入联系电话"
                  :disabled="opt == 'details'"
                  show-word-limit
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="联系人职务" prop="position">
                <el-input
                  v-model="form.position"
                  placeholder="请输入联系人职务"
                  :disabled="opt == 'details'"
                />
              </el-form-item>
            </el-col>
          </el-row>

        <el-row>
        <el-col :span="8">
              <el-form-item label="客户分类" prop="templateClass">
                <el-select
                  v-model="form.templateClass"
                  style="width: 305px"
                  placeholder="请选择客户分类"
                  :disabled="opt == 'details'"
                >
                  <el-option
                    v-for="dict in dict.type.template_class"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="客户类型" prop="enterpriseType">
                <el-select
                  v-model="form.enterpriseType"
                  style="width: 305px"
                  placeholder="请选择客户类型"
                  :disabled="opt == 'details'"
                >
                  <el-option
                    v-for="dict in dict.type.enterprise_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="经营状态" prop="operateStatus">
                <el-select
                  v-model="form.operateStatus"
                  style="width: 305px"
                  placeholder="请选择经营状态"
                  :disabled="opt == 'details'"
                >
                  <el-option
                    v-for="dict in dict.type.operate_status"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="开发经理" prop="developmentManager">
                <el-input
                  v-model="form.developmentManager"
                  :disabled="opt != 'add' && form.enterpriseSource != 14"
                  placeholder="请输入开发经理"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="业务经理" prop="businessManagerNew" >
                <el-input
                  v-model="form.businessManagerNew"
                  placeholder="请选择业务经理"
                  @focus="selectOpen(2)"
                  :disabled="opt == 'details'"
                  :readonly="readonly"
                />
              </el-form-item>
              <el-form-item label="业务经理2" prop="businessManager" v-show="isBusinessManager">
                <el-input
                  v-model="form.businessManager"
                  placeholder="用于存储业务经理id"
                  @focus="selectOpen(2)"
                  :disabled="opt == 'details'"
                  :readonly="readonly"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="创建人" prop="creationName">
                <el-input
                  v-model="form.creationName"
                  placeholder="请输入创建人"
                  disabled="true"
                />
              </el-form-item>
            </el-col>
            <!-- <el-col :span="8">
              <el-form-item label="状态" prop="status">
                <el-select
                  v-model="form.status"
                  style="width: 305px"
                  placeholder="请选择状态"
                  :disabled="opt == 'details'"
                >
                  <el-option
                    v-for="dict in dict.type.enterprise_status"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
          </el-row>

          <el-row>

            <el-col :span="8">
              <el-form-item label="创建时间" prop="creationTime">
                <el-input v-model="form.creationTime" disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="16">
              <el-form-item label="经营范围" prop="businessScope">
                <el-input
                  v-model="form.businessScope"
                  placeholder="请输入经营范围"
                  type="textarea"
                  :autosize="{ minRows: 3, maxRows: 4 }"
                  :disabled="opt == 'details'"
                  maxlength="1000"
                  show-word-limit
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" style="height: 70px">
              <el-form-item label="营业执照">
                <file-view
                  :type="fileType"
                  :businessId="businessId"
                  :businessCode="businessCode"
                  @change="getFile"
                  :key="refreshKey"
                ></file-view>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div style="text-align: center; margin-top: 30px">
          <el-button type="primary" @click="submitForm" v-if="opt != 'details'"
            >保 存</el-button
          >
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane label="跟进记录" name="four" :disabled="isShowTab">
        <div>
          <el-tabs v-model="recordsActiveTab" type="card" class="records-tabs" @tab-click="handleRecordsTabClick">
            <el-tab-pane label="客户记录" name="enterprise">
              <BusinessRecords
                ref="records"
                :bId="bId"
                :enterpriseId="enterpriseId"
                :enterpriseName="form.enterpriseName"
                :contacts="form.contacts"
                :telephone="form.telephone"
                :opt="opt"
                @change="loadList"
                v-if="recordsActiveTab === 'enterprise'"
              ></BusinessRecords>
            </el-tab-pane>
            <el-tab-pane label="线索记录" name="electric">
              <ElectricRecords
                :bId="enterpriseId"
                v-if="recordsActiveTab === 'electric' && form.enterpriseOrgId"
                :isAdd="false"
                @change="loadList"
              ></ElectricRecords>
            </el-tab-pane>
            <el-tab-pane label="公海记录" name="seas">
              <SeasRecords
                :bId="enterpriseId"
                :isAdd="false"
                v-if="recordsActiveTab === 'seas' && form.enterpriseOrgId"
              ></SeasRecords>
            </el-tab-pane>
          </el-tabs>
        </div>
        <div style="text-align: center">
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane label="荣誉资质信息" name="second" :disabled="isShowTab">
        <Honor
          ref="honor"
          @change="loadList"
          :bId="bId"
          :enterpriseId="enterpriseId"
          :enterpriseName="enterpriseName"
          :opt="opt"
        >
        </Honor>
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
      </el-tab-pane>
      <el-tab-pane
        v-if="isCertified"
        label="有效商机信息"
        name="businessinfo"
        :disabled="isShowTab"
      >
        <Businessinfo
          ref="businessinfo"
          @change="loadList"
          :bId="bId"
          :enterpriseId="enterpriseId"
          :enterpriseName="form.enterpriseName"
          :isEnterprise="isEnterprise"
          :is-show-opt="false"
          :opt="opt"
        >
        </Businessinfo>
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
      </el-tab-pane>
      <el-tab-pane label="合同信息" name="contract" :disabled="isShowTab">
        <Contract
          ref="contract"
          @change="loadList"
          :isEnterprise="isEnterprise"
          :bId="bId"
          :enterpriseId="enterpriseId"
          :enterpriseName="form.enterpriseName"
        >
        </Contract>
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
      </el-tab-pane>
<!--      <el-tab-pane label="项目信息" name="project" :disabled="isShowTab">-->
<!--        <Project-->
<!--          ref="project"-->
<!--          @change="loadList"-->
<!--          :isEnterprise="isEnterprise"-->
<!--          :bId="bId"-->
<!--          :enterpriseId="enterpriseId"-->
<!--          :enterpriseName="form.enterpriseName"-->
<!--          :show-close="true"-->
<!--        >-->
<!--        </Project>-->
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
<!--      </el-tab-pane>-->
      <el-tab-pane label="人员信息" name="person" :disabled="isShowTab">
        <Person
          ref="person"
          :bId="bId"
          :enterpriseId="enterpriseId"
          :isEnter="true"
          :enterpriseName="form.enterpriseName"
          :isOpen="isOpen"
          :showClose="false"
          @change="loadList"
          :show-close="true"
          :opt="opt"
        >
        </Person>
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
      </el-tab-pane>
      <el-tab-pane label="项目资金" name="third" :disabled="isShowTab">
        <Funding
          ref="funding"
          @change="loadList"
          :bId="bId"
          :enterpriseId="enterpriseId"
          :isEnterprise="isEnterprise"
          :enterpriseName="form.enterpriseName"
          :opt="opt"
        >
        </Funding>
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
      </el-tab-pane>
      <el-tab-pane label="活动培训" name="activity" :disabled="isShowTab" lazy="true">
        <Activity
          ref="activity"
          @change="loadList"
          :bId="bId"
          :enterpriseId="form.enterpriseOrgId"
          :enterpriseName="form.enterpriseName"
          :show-close="true"
        >
        </Activity>
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
      </el-tab-pane>
      <el-tab-pane label="问卷调查" name="questionnaire" :disabled="isShowTab" lazy="true">
        <Questionnaire
          ref="questionnaire"
          @change="loadList"
          :bId="bId"
          :enterpriseId="form.enterpriseOrgId"
          :enterpriseName="form.enterpriseName"
          :show-close="true"

        >
        </Questionnaire>
<!--        <div style="text-align: center">-->
<!--          <el-button @click="cancel">关 闭</el-button>-->
<!--        </div>-->
      </el-tab-pane>
    </el-tabs>
    <select-user
      ref="select"
      :type="userType"
      :sign="sign"
      @ok="selectUser"
    ></select-user>
    <Collaborative
      ref="collaborate"
      :enterpriseIdOrgId="orgId"
    ></Collaborative>
  </div>
</template>
<script>
import { listTrainingByEnterpriseId } from "@/api/activity/training";
import {
  listInfo,
  getMaxEnterpriseNo,
  getInfo,
  listToName,
  delInfo,
  addInfo,
  updateInfo,
  getHighSeaslistToName,
  getSalelistToName,
  delHighSeasByEnterpriseId,
} from "@/api/enterprise/info";
import {
  listRecords,
  getRecords,
  delRecords,
  addRecords,
  updateRecords,
} from "@/api/enterprise/records";
import { delSeas } from "@/api/highSeas/seas";
import { listElectric, delElectric } from "@/api/electric/electric";
import { id } from "@/api/system/UUID";
import { listArea } from "@/api/area/area";
import FileView from "@/components/FileView/index";
import SelectUser from "../../system/role/selectUser.vue";
import { listType } from "@/api/maintype/type";
//问卷调查
import Questionnaire from "../../questionnaire/reception/index.vue";
//活动培训
import Activity from "../../activity/receive/index.vue";
//跟进记录
import BusinessRecords from "./records.vue";
//电销跟进记录
import ElectricRecords from "../electric/records.vue";
//公海跟进记录
import SeasRecords from "../seas/seasRecords.vue";
//商机信息
import Businessinfo from "../../enterprise/businessinfo/index.vue";
//人员信息
import Person from "../../enterprise/person/index.vue";
// //荣誉资质
// import Honor from "../../honor/index.vue";
//合同信息
import Contract from "../../contract/index.vue";
//项目信息
import Project from "../../project/query/index.vue";
//项目资金
import Funding from "../../project/funding/index.vue";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { getIndustryTree } from "@/api/enterprise/industry";
//查看企业合作的园区平台
import Collaborative from './components/collaborative';
export default {
  name: "Info",
  dicts: [
    "belong_to_park",
    "customer_industry_serve",
    "customer_industry_garden",
    "sys_org_type",
    "enterprise_nature",
    "customer_industry",
    "enterprise_records",
    "enterprise_status",
    "enterprise_source",
    "enterprise_type",
    "operate_status",
    "register_status",
    "template_class",
    "customer_industry_new"
  ],
  components: {
    Collaborative,
    Questionnaire,
    Activity,
    Treeselect,
    SelectUser,
    Contract,
    Project,
    FileView,
    Funding,
    Businessinfo,
    Person,
    BusinessRecords,
    ElectricRecords,
    SeasRecords,
    Honor: () => import("@/views/honor/index.vue"),
  },
  props: {
    opt: {
      type: String,
      default: "",
    },
    newMarkAs: {
      type: String,
      default: "",
    },

    seas: {
      type: String,
      default: "0",
    },
    id: {
      type: String,
      default: "",
    },
    getId: {
      type: String,
      default: "",
    },
    obj: {
      type: Object,
      default: null,
    },
    //序号
    index: {
      type: Number,
      default: 0,
    },
    classId: {
      type: Number,
      default: 0,
    },
    enterpriseName:{
      type:String,
      default:null
    },
    orgId: {
      type: String,
      default: null,
    },
  },
  data() {
    var developmentManager = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("开发经理不能为空"));
      }
      return callback();
    };

    var businessManager = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("业务经理不能为空"));
      }
      return callback();
    };

    // var administrativeAreaChange = (rule, value, callback) => {
    //     value = this.form.administrativeArea
    //     if (!value) {
    //         return callback(new Error('行政区域不能为空'));
    //     }
    //     return callback()
    // };
    // var contacts = (rule, value, callback) => {
    //     if (!value) {
    //         return callback(new Error('联系人不能为空'));
    //     }
    //     return callback()
    // };
    return {
      industryType: 0,
      optNew: "",
      isCertified: false,
      isEnterprise: true,
      lable: null,
      saleId: null,
      refreshKey: 0,
      noNew: "KH",
      enterpriseNo: "",
      readonly: true,
      opt1: false,
      opt2: false,
      opt3: false,
      checkCount: 0,
      isShowTab: true,
      isShowTabSJ: true,
      isOpen: false,
      UUID: "",
      userType: "1",
      optionData: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      queryHighSeas: {
        pageNum: 1,
        pageSize: 15,
        enterpriseId: null,
        administrativeArea: null,
        enterpriseNature: null,
        industry: null,
        //classificationId: null
      },
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //行政区域
      options: null,
      // 企业信息表格数据
      recordsList: [],
      businessCode: "enterprise", //营业执照
      enterpriseinfo: "enterpriseinfo",
      // 弹出层标题
      title: "",
      sign: "1",
      honorShow: "0",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        //industryType:"0",
        enterpriseId: null,
      },
      // 表单参数
      form: {
        industryType: "0",
        creationName: this.$store.state.user.info.nickName,
        creationTime: this.parseTime(new Date(), "{y}-{m}-{d}"),
        industry: null, // 行业ID
        industryId: null, // 后端存储的行业ID
      },
      // 表单校验
      rules: {
        registeredCapital: [
          { required: true, message: "注册资金不能为空", trigger: "blur" },
        ],
        enterpriseName: [
          { required: true, message: "企业名称不能为空", trigger: "blur" },
          { max: 50, message: "企业名称长度不能超过50", trigger: "blur" },
        ],
        enterpriseAddress: [
          { required: true, message: "详细地址不能为空", trigger: "blur" },
          { max: 499, message: "详细地址长度不能超过500字", trigger: "blur" },
        ],
        administrativeArea: [
          //{ required: true, validator: administrativeArea, trigger: "change" }
          { required: true, message: "行政区域不能为空", trigger: "blur" },
        ],

        enterpriseNature: [
          { required: true, message: "企业性质不能为空", trigger: "change" },
        ],
        enterpriseSource: [
          { required: true, message: "企业来源不能为空", trigger: "change" },
        ],
        // status: [
        //   { required: true, message: "状态不能为空", trigger: "change" },
        // ],
        legalRepresentative: [
        { required: true, message: "法人代表不能为空", trigger: "blur" },
        ],
        establishmentDate: [
          { required: true, message: "成立日期不能为空", trigger: "change" }
        ],
        // bankNo: [
        //   { required: true, message: "开户账号不能为空", trigger: "blur" }
        // ],
        // bankName: [
        //   { required: true, message: "开户银行不能为空", trigger: "blur" }
        // ],
        // personNum: [
        //   { required: true, message: "企业人数不能为空", trigger: "blur" },
        // ],
        operateStatus: [
          { required: true, message: "经营状态不能为空", trigger: "change" }
        ],
        templateClass: [
          { required: true, message: "客户分类不能为空", trigger: "change" }
        ],
        taxId: [
          { required: true, message: "税务号不能为空", trigger: "blur" }
        ],
        businessScope: [
          { required: true, message: "经营范围不能为空", trigger: "blur" },
        ],
        enterpriseType: [
          { required: true, message: "客户类型不能为空", trigger: "change" }
        ],
        contacts: [
          { required: true, message: "联系人姓名不能为空", trigger: "blur" },
          { max: 36, message: "联系人姓名长度不能超过36", trigger: "blur" },
        ],
        telephone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
          { max: 50, message: "联系电话长度不能超过50", trigger: "blur" },
        ],
        position: [
          { required: true, message: "联系人职务不能为空", trigger: "blur" },
          { max: 20, message: "联系人职务长度不能超过20", trigger: "blur" },
        ],
        // businessId: [
        //  { required: false, message: "营业执照不能为空", trigger: "change" }
        // ],
        developmentManager: [
          { required: true, validator: developmentManager, trigger: "change" },
        ],
        businessManagerNew: [
          { required: true, validator: businessManager, trigger: "change" },
        ],

        industry: [
          { required: true, message: "所属行业不能为空", trigger: "change" },
        ],
      },
      queryParamsElectric: {
        pageNum: 1,
        pageSize: 15,
        enterpriseName: null,
        enterpriseAddress: null,
        enterpriseNature: null,
        electricType: null,
        //classificationId: null
      },
      //复选框
      markAs: null,
      //选显卡默认选中
      activeName: "first",
      //
      show: "",
      //上传按钮隐藏
      isShow: true,
      url: "",
      isBusinessManager:false,
      fileType: 0,
      businessId: null,
      zValue: 0,
      industryOptions: [], // 行业树形数据
      loadedTabs: {
        first: false,
        second: false,
        third: false,
        fourth: false
      },
      recordsActiveTab: "enterprise",
    };
  },
  watch: {
    obj(newVal) {
      this.refreshKey++;
      this.form = newVal;
      this.businessId = newVal.enterpriseId;
      this.markAs = this.form.markAs;
      this.opt1 = true;
      this.opt2 = true;
      this.opt3 = true;
      this.$forceUpdate();
    },
  },
  created() {

    if (this.$store.state.user.info.companyType != "0") {
      this.isCertified = true;
    }
    //this.handleClick();
    this.listType();
    this.area();
    this.getMaxEnterpriseNoNo();
    let url = window.location.href;
    // 获取参数部分
    let params = url.split("?")[1];
    if (this.newMarkAs == 1) {
      this.opt1 = true;
      this.markAs = "1";
    } else if (this.newMarkAs == 2) {
      this.opt2 = true;
      this.markAs = "2";
    } else {
      this.opt3 = true;
      this.markAs = "3";
    }

    //新增
    if (this.opt == "add") {
      this.fileType = 0;
      this.businessId = this.getId;
      this.enterpriseId = this.getId;
      this.bId = this.getId;
      const no = 0;
      getMaxEnterpriseNo().then(response => {
        if (response == "" || response == null) {
          this.form.enterpriseNo = "KH0001";
        } else {
          if (parseInt(response) > 100) {
            this.noNew += "0" + parseInt(response + 1);
          } else if (parseInt(response) >= 1 && parseInt(response) < 10) {
            this.noNew += "000" + parseInt(response + 1);
          } else if (parseInt(response) >= 10 && parseInt(response) < 100) {
            this.noNew += "00" + parseInt(response + 1);
          }
          this.form.enterpriseNo = this.noNew;
        }
      });

    } //编辑
    if (this.opt == "edit") {
      this.refreshKey++;
      //alert(this.obj.areaName)
      //this.form.administrativeArea = this.obj.areaName
      this.isShowTab = false;
      this.fileType = 1;
      this.businessId = this.id;
      this.bId = this.id;
      this.enterpriseId = this.id;

      this.handleUpdate(this.id);
    }
    if (this.opt == "details") {
      this.refreshKey++;
      //this.form.administrativeArea = this.obj.areaName
      this.opt1 = true;
      this.opt2 = true;
      this.opt3 = true;
      this.fileType = 2;
      this.isShowTab = false;
      this.isShowTabSJ = false;
      this.enterpriseId=this.id;
      this.handleUpdate(this.id);
      if (this.obj != null) {
        //this.form = this.obj
        //this.form.administrativeArea = this.obj.areaName
        //console.log(this.form)
        //
        this.markAs = this.form.markAs;
        this.businessId = this.obj.enterpriseId;
      }
    }
    this.getIndustryTree();
  },
  methods: {

    //查看合作的园区平台
    queryCollaborative() {
      this.$refs.collaborate.show();
      if(this.opt!="add"){

      }
    },
    administrativeAreaChange(val) {
      // console.log('parentId变化', val);
      this.$nextTick(() => {
        this.$refs["form"].validateField("administrativeArea");
      });
    },
    // classificationIdChange(val) {
    // // console.log('parentId变化', val);
    //     this.$nextTick(() => {
    //         this.$refs["form"].validateField('classificationId');
    //     })
    // },

    handleRadioChange(value) {
      //this.form.industry = ""
      this.industryType = value;
      if (value == 0) {
        this.dict.type.customer_industry.forEach(item => {
          if (
            item.value != this.form.industry &&
            this.form.industry != "undifend" &&
            this.form.industry != null &&
            this.form.industry != ""
          )
            this.form.industry = "";
        });
      }
      if (value == 1) {
        this.dict.type.customer_industry_serve.forEach(item => {
          if (
            item.value != this.form.industry &&
            this.form.industry != "undifend" &&
            this.form.industry != null &&
            this.form.industry != ""
          )
            this.form.industry = "";
        });
      }
      if (value == 2) {
        this.dict.type.customer_industry_garden.forEach(item => {
          if (
            item.value != this.form.industry &&
            this.form.industry != "undifend" &&
            this.form.industry != null &&
            this.form.industry != ""
          )
            this.form.industry = "";
        });
      }
    },
    loadList() {
      this.$emit("change", this.zValue);
    },
    getMaxEnterpriseNoNo() {},
    handlerPageNo(value) {
      this.queryParams.enterpriseName = value;
      this.queryParamsElectric.enterpriseName = value;
      getHighSeaslistToName(this.queryParams).then(response => {
        if (response.total > 0) {
          this.$modal
            .confirm("该企业已存在于公海/电销中,是否获取该数据信息?")
            .then(function () {
              return value;
            })
            .then(() => {
              this.reset();
              //this.form = response.rows[0];
              this.saleId = response.rows[0].enterpriseId;
              this.businessId = response.rows[0].enterpriseId;
              if (response.rows[0].hasOwnProperty('enterpriseId')){
                this.form.enterpriseId = response.rows[0].enterpriseId;
                this.lable = 2;
              }else {
                this.form.enterpriseId=response.rows[0].electricId
                this.lable = 1;
              }
              console.log("公海数据,湖南胜铭内燃机配件制造有限公司",response)
              //this.form.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7'
              //this.form.enterpriseNo = response.rows[0].companyNo
              this.form.enterpriseName = response.rows[0].enterpriseName
              this.form.enterpriseSource = response.rows[0].enterpriseSource
              this.form.enterpriseAbbreviation = response.rows[0].enterpriseAbbreviation
              this.form.administrativeArea = response.rows[0].administrativeArea
              this.form.legalRepresentative = response.rows[0].legalRepresentative
              this.form.establishmentDate = response.rows[0].establishmentDate
              this.form.operateStatus = "0"
              this.form.industry = response.rows[0].industry
              this.form.contacts = response.rows[0].contacts
              this.form.telephone = response.rows[0].telephone
              this.form.taxId = response.rows[0].taxId
              this.form.businessScope = response.rows[0].businessScope
              this.form.registeredCapital = response.rows[0].registeredCapital
              this.form.enterpriseAddress = response.rows[0].enterpriseAddress
              this.form.enterpriseNature = response.rows[0].enterpriseNature
              this.form.creationName = this.$store.state.user.name;
              if(response.rows[0].account!=null){
                this.form.bankNo = response.rows[0].account
              }
              if(response.rows[0].accountBank!=null){
                this.form.bankName = response.rows[0].accountBank
              }
              this.form.developmentId = response.rows[0].developManager //开发
              this.form.developmentManager = response.rows[0].developmentName //开发
              this.form.creationTime = this.parseTime(new Date(), "{y}-{m}-{d}")
              this.$modal.msgSuccess("操作成功");
              this.refreshKey++;
            })
            .catch(() => {
              this.form.enterpriseName = "";
            });
        }
      });
    },

    getFile(data) {
      //console.log(JSON.stringify(data))
    },
    // 取消按钮
    cancel() {
      this.reset();
      this.$emit("change");
    },
    rowAdd() {
      this.recordsList.push({
        recordsId: new Date().getTime(),
        followTime: this.parseTime(new Date(), "{y}-{m}-{d} {hh}:{ss}"),
        followPerson: this.$store.state.user.name,
        annex: new Date().getTime(),
        sign: "1",
      });
    },
    handlesubmit(row) {
      row.enterpriseId = this.form.enterpriseId;
      addRecords(row).then(response => {
        this.$modal.msgSuccess("保存成功");
      });
    },
    area() {
      listArea({}).then(response => {
        this.options = [];
        console.log(response.data);
        this.options = response.data;
      });
    },
    selectUser(userId, userName, phone,position,nickName) {
      console.log("业务经理",userId,nickName);
      if (this.show == "2") {
        this.$set(this.form, "businessManagerNew", nickName);
        this.$set(this.form, "businessManager", userName);
        this.$set(this.form, "transactionId", userId);
      } else if (this.show == "1") {
        this.$set(this.form, "developmentManager", nickName);
        this.$set(this.form, "developmentId", userId);
      }
    },
    //获取树节点数据
    listType() {
      listType({ typeCode: "enterprise" }).then(res => {
        this.optionData = res.data;
      });
    },
    selectOpen(type) {
      this.show = type;
      this.$refs.select.show();
    },
    selectActiveName() {
      this.activeName = "first";
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      //this.businessId = this.getId()
      this.open = true;
      this.title = "添加企业信息";
    },
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.areaId,
        label: node.areaName,
        isDisabled: false,
        children: node.list && node.list.length > 0 ? node.list : 0,
      };
    },
    close(data) {
      this.getList();
    },
    /** 修改按钮操作 */
    handleUpdate(id) {
      this.reset();
      getInfo(id).then(response => {
        console.log("企业信息",response.data)
        this.enterpriseName = response.data.enterpriseName

        this.industryType = response.data.industryType;
        this.index = response.data.enterpriseName;
        if (response.data.enterpriseNo > 100) {
          response.data.enterpriseNo = "KH0" + response.data.enterpriseNo;
        } else if (
          response.data.enterpriseNo >= 1 &&
          response.data.enterpriseNo < 10
        ) {
          response.data.enterpriseNo = "KH000" + response.data.enterpriseNo;
        } else if (
          response.data.enterpriseNo >= 10 &&
          response.data.enterpriseNo < 100
        ) {
          response.data.enterpriseNo = "KH00" + response.data.enterpriseNo;
        }
        this.form = response.data;
        this.form.businessManagerNew = response.data.businessManager;
        this.markAs = this.form.markAs;
        this.recordsList = response.data.records;
      });
    },
    handleDelete(row) {
      const recordsIds = row.recordsId;
      this.$modal
        .confirm("是否确认删除企业跟进记录？")
        .then(function () {
          return delRecords(recordsIds);
        })
        .then(() => {
          for (let index = 0; index < this.recordsList.length; index++) {
            const element = this.recordsList[index];
            if (recordsIds == element.recordsId) {
              this.recordsList.splice(index, 1);
              break;
            }
          }
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 提交按钮 */
    submitForm() {
      console.log("保存",this.form)
      //this.checkCount=1;
      if (this.opt == "add" || this.opt == "edit") {
        this.form.enterpriseLabel = this.lable;
        this.form.enterpriseAbbreviation = this.saleId;
        this.form.markAsName = this.markAs;
        this.$refs["form"].validate(valid => {
          let noTwo;
          if (valid) {
            let data = Object.assign({}, this.form);
              data.markAs = this.markAs;
              // 处理行业数据
              if (data.industry) {
                data.industryId = data.industry; // 保存行业ID
              }
              if (this.opt == "add") {
                if(data.enterpriseId == undefined || data.enterpriseId== null){
                  data.enterpriseId = this.getId;
                }
                getMaxEnterpriseNo().then(responseNo => {
                  if (responseNo == "" || responseNo == null) {
                      data.enterpriseNo = 1;
                    } else {
                      data.enterpriseNo = parseInt(responseNo + 1);
                    }
                    updateInfo(data).then(response => {
                      this.opt = "edit";
                      this.fileType = 1;
                      this.optNew = "new";
                      this.index = data.enterpriseName;
                      this.isShowTab = false;
                      this.$modal.msgSuccess("保存成功");
                      this.lable=null;
                      this.refreshKey++;
                    });
                });
              } else {
                getMaxEnterpriseNo().then(responseNoTwo => {
                  this.noTwo = responseNoTwo;
                });
                if (this.optNew == "new") {
                  data.enterpriseId = this.getId;
                }
                data.enterpriseNo = this.noTwo;
                updateInfo(data).then(response => {
                  this.isShowTab = false;
                  this.$modal.msgSuccess("保存成功");
                  this.lable=null;
                  this.refreshKey++;
                });
              }
            // if (this.form.url===null || this.form.url===""){
            //   this.$message.error("请上传营业执照");
            // }else {

            // }
          }
        });
      }
    },
    guId() {
      function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
      }
      return (
        S4() +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        S4() +
        S4()
      );
    },

    // 表单重置
    reset() {
      this.form = {
        enterpriseId: null,
        enterpriseName: null,
        enterpriseSource: null,
        enterpriseAbbreviation: null,
        areaName: null,
        administrativeArea: null,
        legalRepresentative: null,
        establishmentDate: null,
        contractAmount: null,
        enterpriseLabel: null,
        registeredCapital: null,
        industry: null,
        contacts: null,
        telephone: null,
        bankName: null,
        taxId: null,
        developmentId: null,
        transactionId: null,
        developmentManager: null,
        businessManager: null,
        enterpriseAddress: null,
        businessScope: null,
        enterpriseType: null,
        enterpriseNature: null,
        markAs: null,
        belongTo: null,
        creationTime: null,
        operateTime: null,
        operateId: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        delFlag: null,
        status: null,
        personNum:null,
        registerStatus:null,
        operateStatus:null,
        templateClass:null
      };
      this.resetForm("form");
    },

    loadFirstTabData() {
      // Move enterprise info loading logic here
      this.getEnterpriseInfo();
      this.loadedTabs.first = true;
    },

    // loadSecondTabData() {
    //   // Move business data loading logic here
    //   this.getBusinessData();
    //   this.loadedTabs.second = true;
    // },

    loadThirdTabData() {
      // Move records data loading logic here
      this.getRecordsData();
      this.loadedTabs.third = true;
    },

    loadFourthTabData() {
      // Move satisfaction data loading logic here
      this.getSatisfactionData();
      this.loadedTabs.fourth = true;
    },

    // Modify the tab click handler
    handleClick(tab) {
      const tabName = tab.name;
      if (!this.loadedTabs[tabName]) {
        switch(tabName) {
          case 'first':
            this.loadFirstTabData();
            break;
          case 'second':
            this.loadSecondTabData();
            break;
          case 'third':
            this.loadThirdTabData();
            break;
          case 'fourth':
            this.loadFourthTabData();
            break;
        }
      }
    },

    // Modify the init method to only load first tab data
    init() {
      if (this.opt !== 'add') {
        this.loadFirstTabData();
      }
      // ... rest of init logic ...
    },
    // 获取行业树形数据
    getIndustryTree() {
      getIndustryTree().then(response => {
        if (response.code === 200) {
          this.industryOptions = response.data;
          console.log('行业数据:', this.industryOptions);
        } else {
          this.$modal.msgError(response.msg);
        }
      }).catch(error => {
        console.error('获取行业数据失败:', error);
        this.$modal.msgError('获取行业数据失败');
      });
    },

    // 格式化行业树形数据
    industryNormalizer(node) {
      return {
        id: node.industryId,
        label: node.name,
        children: node.children && node.children.length > 0 ? node.children : null
      };
    },
    // 处理行业选择变化
    handleIndustryChange(value) {
      if (value) {
        // 根据选择的行业ID更新industryType
        const findIndustryType = (options, targetId) => {
          for (const option of options) {
            if (option.industryId === targetId) {
              // 根据行业的层级设置industryType
              this.form.industryType = option.levelType === 1 ? "0" :
                                      option.levelType === 2 ? "1" : "2";
              return true;
            }
            if (option.children) {
              if (findIndustryType(option.children, targetId)) {
                return true;
              }
            }
          }
          return false;
        };

        findIndustryType(this.industryOptions, value);
      }
    },
    handleRecordsTabClick(tab) {
      const tabName = tab.name;
      if (!this.loadedTabs[tabName]) {
        switch(tabName) {
          case 'enterprise':
            this.loadFirstTabData();
            break;
          case 'electric':
            this.loadSecondTabData();
            break;
          case 'seas':
            this.loadThirdTabData();
            break;
        }
      }
    },
  },
};
</script>
<style scoped>
 ::v-deep  .el-tag--medium{
    height: 29px;
    line-height: 29px;
  }
 .teacher-form-container {
   overflow-y: auto;
   overflow-x: auto;
   padding: 16px;
   max-width: 100%;
   max-height: 80vh;
   box-sizing: border-box;
 }

 /* .vue-treeselect__single-value{
   color: #c0c4cc;

 }
 .vue-treeselect__value-container{
     background-color: #F5F7FA;
 }
 .vue-treeselect__control-arrow-container{
     background-color: #F5F7FA;
 } */

.records-tabs {
  margin-bottom: 20px;
}

::v-deep .records-tabs .el-tabs__header {
  margin-bottom: 15px;
}

::v-deep .records-tabs .el-tabs__nav {
  border-radius: 4px;
}

::v-deep .records-tabs .el-tabs__item {
  height: 36px;
  line-height: 36px;
  font-weight: 500;
}

::v-deep .records-tabs .el-tabs__item.is-active {
  background-color: #409EFF;
  color: white;
  border-radius: 4px;
}
</style>
